//
//  MainViewController.swift
//  Weibo
//
//  Created by mac on 16/1/10.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChildViewControllers()

        let mainTabBar: MainTabBar = MainTabBar()
        
        mainTabBar.plusBtn.addTarget(self, action: "plusBtnClick", forControlEvents: .TouchUpInside)
        self .setValue(mainTabBar, forKey: "tabBar")
    }
    
   @objc private func plusBtnClick(){
        print("=====")
    }

   private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    
   private func addChildViewController(childController: UIViewController,title:String, imageName:String) {
        
        
        childController.title = title
        
        let norImage: UIImage = UIImage(named: imageName)!.imageWithRenderingMode(.AlwaysOriginal)
        let selImage: UIImage = UIImage(named: imageName + "_highlighted")!.imageWithRenderingMode(.AlwaysOriginal)
        
        childController.tabBarItem.image = norImage
        childController.tabBarItem.selectedImage = selImage
        
        let nav: UINavigationController = UINavigationController(rootViewController: childController)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState:.Selected)
    
        
        addChildViewController(nav)
        
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
